<?php
/**
 * Created by PhpStorm.
 * User: 我型我素
 * Date: 2018/1/31
 * Time: 16:25
 */

namespace App\Services\Orders;


use App\Services\Bonus\BonusService;
use App\Services\Cart\CartService;

class CheckOutService
{

    protected $orderService;

    protected $cartService;

    protected $bonusService;

    public function __construct(OrderService $orderService,
                                CartService $cartService,
                                BonusService $bonusService)
    {
        $this->orderService = $orderService;
        $this->cartService = $cartService;
        $this->bonusService = $bonusService;
    }

    public function PrepareOrderSettlement($param){
        $cartInfo=$this->cartService->getGoodsForOrder($param['user_id'],$param['bonus_id']);

        $data = $cartInfo;
        return $data;
        $data['cart_goods_list_group'] = $this->orderService->getCartGoodsGroupList($cartInfo['goods_list'],false);

        $data['bonus_list'] = $this->checkCanUseBonus($cartInfo,$param);

        return $data;
    }


    private function checkCanUseBonus($cartInfo,$param){
        $bonus_param = [];
        $bonus_param['cart_goods'] = $cartInfo['goods_list'];
        $bonus_param['goods_amount'] = $cartInfo['total']['goods_amount'];
        $bonus_param['shopping_type'] = $param['shopping_type'];
        $bonus_param['wid'] = $param['wid'];
        if(!empty($param['date'])){
            $bonus_param['date'] = $param['date'];
        }

        $bonus_list = $this->bonusService->getOrderCanUseBonus($param['user_id'],$bonus_param);

        return $bonus_list;
    }
}